package com.pr.makfilm.user.pages.room.create.preview;

import com.google.common.collect.Table;
import com.pr.makfilm.domain.Room;
import com.pr.makfilm.domain.RoomPlace;
import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

/**
 * Created with IntelliJ IDEA.
 * User: Pawel
 * Date: 09.10.13
 * Time: 17:45
 * To change this template use File | Settings | File Templates.
 */
public class PreviewCellRepeater extends RepeatingView
{
   private IModel<Table> placesModel;

   private int rowId;

   public PreviewCellRepeater(String id, IModel<?> model, IModel<Table> placesModel, int rowId)
   {
      super(id, model);
      this.placesModel = placesModel;
      this.rowId = rowId;
   }

   @Override
   protected void onPopulate()
   {
      removeAll();
      Room room = (Room) getDefaultModelObject();
      for (int colId = 0; colId < room.getColumnCount(); colId++)
      {
         Table<Integer, Integer, RoomPlace> table = placesModel.getObject();
         RoomPlace place = table.get(rowId, colId);
         PreviewCell cell = new PreviewCell(newChildId(), Model.of(place));
         add(cell);
      }
   }
}
